package online.heycm.platform.web.common;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * Spring 上下文
 *
 * @author hey
 * @version 1.0
 * @date 2024/1/18 14:58
 */
public class SpringContextImpl implements ApplicationContextAware, SpringContext {

    private ApplicationContext applicationContext;

    @Override
    public Object getBean(String beanName) {
        return applicationContext.getBean(beanName);
    }

    @Override
    public <T> T getBean(String beanName, Class<T> beanType) {
        return applicationContext.getBean(beanName, beanType);
    }

    @Override
    public <T> T getBean(Class<T> requiredType) {
        return applicationContext.getBean(requiredType);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }
}
